function checkAll(obj) {
  var checks = document.getElementsByName("checkShop");
  for (var i = 0; i < checks.length; i++) {
    checks[i].checked = obj.checked;
  }
}

function jdcheckAll(th) {
  var checkitems = document.getElementsByName("checkItem");
  var flag = th.checked;
  for (var i in checkitems) {
    checkitems[i].checked = flag;
  }
  goods();
}
function goods() {
  var selected = document.getElementsByName("checkItem");
  var price = document.getElementsByClassName("p-sum");
  var sum = 0;
  var flag = true;
  var amount = 0;
  for (var i = 0; i < selected.length; i++) {
    if (!selected[i].checked) {
      flag = false;
    } else {
      amount += 1;
      var priceall = price[i].firstElementChild.innerHTML;
      sum += parseFloat(priceall.substring(priceall.indexOf("¥") + 1));
    }
  }
  checkALL.checked = flag;
  checkALL1.checked = flag;
  document.getElementById("amountall").innerHTML = amount;
  document.getElementById("allsum").innerHTML = "¥" + sum.toFixed(2);
}

function add(obj) {
  var num = obj.previousElementSibling.firstElementChild.value;

  num++;
  obj.previousElementSibling.firstElementChild.value = num;
  var price = parseFloat(
    obj.parentNode.parentNode.previousElementSibling.firstElementChild.innerHTML
  );
  var subPrice = price * num;
  obj.parentNode.parentNode.nextElementSibling.firstElementChild.innerHTML =
    "¥" + subPrice.toFixed(2);
  goods();
}
function mius(obj) {
  var num = obj.nextElementSibling.firstElementChild.value;

  num--;
  if (num < 1) {
    alert("数量不能小于1");
    return;
  }
  obj.nextElementSibling.firstElementChild.value = num;
  var price = parseFloat(
    obj.parentNode.parentNode.previousElementSibling.firstElementChild.innerHTML
  );
  var subPrice = price * num;
  obj.parentNode.parentNode.nextElementSibling.firstElementChild.innerHTML =
    "¥" + subPrice.toFixed(2);
  goods();
}
function attention() {
  alert("关注成功！");
}
function del() {
  if (window.confirm("是否确认删除")) {
    alert("已删除");
  } else {
    alert("已取消");
  }
}
